package com.jvyou.thread.test03;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/31 15:51
 * @Description
 */
public class OddThread implements Runnable {

    int count = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (count >= 100) {
                    break;
                } else {
                    count++;
                    if (count % 2 == 1) {
                        System.out.println(Thread.currentThread().getName() + ">" + count);
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        OddThread oddThread = new OddThread();
        Thread t1 = new Thread(oddThread, "多来A梦");
        Thread t2 = new Thread(oddThread, "大雄");
        t1.start();
        t2.start();
    }
}
